package com.xiaoma.h5testdemo.common.ui

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.viewbinding.ViewBinding
import com.xiaoma.h5testdemo.common.dialog.XmImitateDialog

/**
 * author: liangjingbo
 * date: 2023/11/22
 * describe:
 */
open class XmJsDialog<VB : ViewBinding>(
    inflate: (LayoutInflater, ViewGroup?, Boolean) -> VB
) : XmImitateDialog<VB>(inflate) {

    protected val mBuilder = Builder()

    fun onNegativeButton(listener: () -> Unit): XmJsDialog<VB> {
        mBuilder.mNegativeButtonListener = listener
        return this
    }

    fun onPositiveButton(listener: () -> Unit): XmJsDialog<VB> {
        mBuilder.mPositiveButtonListener = listener
        return this
    }

    fun setup(setupBlock: (Builder) -> Unit): XmJsDialog<VB> {
        setupBlock.invoke(mBuilder)
        return this
    }

    override fun getParams(): ConstraintLayout.LayoutParams {
        val lp = ConstraintLayout.LayoutParams(720, ViewGroup.LayoutParams.WRAP_CONTENT)
        lp.startToStart = ConstraintLayout.LayoutParams.PARENT_ID
        lp.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID
        lp.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
        lp.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID
        lp.startToStart = ConstraintLayout.LayoutParams.PARENT_ID
        return lp
    }

    override fun canRestore(): Boolean {
        return false
    }

}

class Builder {
    var mContentText: String? = null
    var mPositiveButtonListener: (() -> Unit)? = null
    var mNegativeButtonListener: (() -> Unit)? = null
}